-- card: 6097 from stack: in -- bmap block id: 0 -- flags: 0000 -- background id: 2253 -- name: hp2pict.inc.c -- part contents for background part 1 ----- text ----- hp2pict.inc.c -- part contents for background part 6 ----- text ----- /* hp2pict.inc.c * * * Copyright 1990 by d.g.gilbert. * dogStar Software && Indiana University Biology Dept. * email: don.gilbert@iubio.bio.indiana.edu * */ /* hp2pict routines & data */ /* A4: 10800 x, 7680 y -- GCG driver: 10170-44x, 7840-384y */ /* A3: 15200 x, 10800 y -- GCG driver: 16000-0x, 10170-34y*/ #define hpPageX 10800 /*10170 - 44 */ #define hpPageY 7456 /*7680 */ #define LBEND '~' /* LaBel end char, was 3 (^C), need non-control to work in HCard field... '†' -- !! HI ascii is missed by this C !! */ /*!! dashline & dashstop postscript mess up my LN03R ps w/ hacked apple ps dictionary, also LaserWRiter refused to print it */ void dashline( int dashlength) { #define DashedLine 180 typedef struct { char offset; char centered; char dashed[2]; /* ?? longer for patterned dash */ } tDashedLine, *pDashedLine, **hDashedLine; hDashedLine hdash; (Handle) hdash = NewHandle(sizeof(tDashedLine)); (**hdash).offset = 0; /* ?? */ (**hdash).centered = 1; /* ?? */ (**hdash).dashed[0] = 1; /* ?? */ (**hdash).dashed[1] = dashlength; /* ?? */ PicComment( DashedLine, GetHandleSize((Handle)hdash), (Handle) hdash); DisposHandle( (Handle)hdash); } void dashstop(void) { #define DashedStop 181 PicComment( DashedStop, 0, NULL); } void lineit(int linetype, int dashsize) { /* ?? need turtlegraphics to do dashed lines ? */ /* not working yet */ switch (linetype) { case 0: /* dashstop(); */ break; default: case 1: case 2: case 3: case 4: case 5: case 6: dashsize = dashsize; /* dashline(dashsize); */ break; } } void laserline( int num, int denom) /* set postscript line width (rel to 1/72 dpi); use num=1, denom=4 for 1/300 dpi line */ { #define SetLineWidth 182 Point **linesize; (Handle) linesize = NewHandle(sizeof(Point)); (**linesize).v = num; (**linesize).h = denom; PicComment( SetLineWidth, sizeof(Point), (Handle) linesize); DisposHandle( (Handle) linesize); } /*laserline*/ void drawUpstr(int h, int v, int rotnum, char *s) { #define maxd 24 #define maxdb 4 /* must be even */ #define maxw 816 /* was 512 */ #define maxwb 102 /* was 64 -- must be even */ typedef char sbitarray[maxd][maxwb]; typedef char tbitarray[maxw][maxdb]; sbitarray *sbits, *sbit2; tbitarray *tbits; Ptr tp; int w,d,i,j; Rect tor, sor; FontInfo fi; BitMap smap, smap2, tmap; GrafPtr aport, offport; GetPort( &aport); /* !! may be CGrafPort w/ pixmap */ GetFontInfo(&fi); d = min(maxd-1, fi.ascent + fi.descent + fi.leading); w = min(maxw-1, stringwidth(s)); /* h = h - (d / 2); */ /*let h,v == topleft not center*/ /* v = v - (w / 2); */ SetRect( &tor, h, v, h + d, v + w); SetRect( &sor, h, v, h + w, v + d); (Ptr)sbits = NewPtr(sizeof(sbitarray)); for (i=0; itxFont); TextSize( aport->txSize); TextFace( aport->txFace); MoveTo(0, fi.ascent); drawstring(s); /* draw the bugger */ ClosePort( offport); DisposPtr( (Ptr)offport); SetPort( aport); switch (rotnum) { case 2: /* 180° ???*/ for (i=0; i < w; i++) { for (j = 0; j < d; j++) if (BitTst( &((*sbits)[j][0]), i)) BitSet( &((*sbit2)[d-j][0]), w-i); } OffsetRect( &sor, -w, 0/*-d*/); /* ? */ CopyBits( &smap2, &(aport->portBits), &smap2.bounds, &sor, srcOr, NULL); DisposPtr( (Ptr)sbit2); break; case 0: /* here for completeness, or just drawstring */ CopyBits( &smap, &(aport->portBits), &smap.bounds, &sor, srcOr, NULL); break; case 3: /* = 270°, bottom left is start */ for (i = w - 1; i >= 0; i--) { tp = &((*tbits)[w - (i + 1)][0]); for ( j = 0; j < d; j++) if (BitTst( &((*sbits)[j][0]), i)) BitSet(tp, j); } OffsetRect( &tor, -d, -w); /* ! */ CopyBits( &tmap, &(aport->portBits), &tmap.bounds, &tor, srcOr, NULL); DisposPtr( (Ptr)tbits); break; case 1: /* = 90°, top right is start */ for (i = 0; i= 0; j--) if (BitTst( &((*sbits)[j][0]), i)) BitSet(tp, d - (j + 1)); } CopyBits( &tmap, &(aport->portBits), &tmap.bounds, &tor, srcOr, NULL); DisposPtr( (Ptr)tbits); break; } DisposPtr( (Ptr)sbits); } /* drawUpstr */ void textPicDraw(int h, int v, int rot, char *s) { /* MacDraw standard drawString w/ rotation h,v = _center_ of text rect */ #define textBegin 150 #define textEnd 151 #define textCenter 154 typedef struct { char tjus; /* 0..4 == left,cent,right,full just */ char tflip; /* 0..2 == 0,horiz,vert flip */ short trot; /* 0..360 rotate */ char tline; /* 1,2,3 line spacing */ char tcmnt; /* reserved */ } TxtPicRec, *pTxtPicRec, **hTxtPicRec; typedef struct { Fixed y, x; } TxtCenter, *pTxtCenter, **hTxtCenter; int w, d, rotnum; Rect zerorect; FontInfo fi; hTxtPicRec picdat; hTxtCenter xydat; RgnHandle saveclip; rotnum = ((rot+44) % 360) / 90; GetFontInfo( &fi); d = (fi.ascent + fi.descent + fi.leading) / 2; w = stringwidth(s) / 2; MoveTo( h, v); /* ?? for HP text */ /* MoveTo(h - w, v - d); */ /* move from center */ (Handle) picdat = NewHandle(sizeof(TxtPicRec)); (**picdat).tjus = 0; (**picdat).tflip = 0; (**picdat).trot = rot % 360; (**picdat).tline = 1; (**picdat).tcmnt = 0; PicComment(textBegin, 6, (Handle) picdat); DisposHandle( (Handle) picdat); (Handle)xydat = NewHandle(sizeof(TxtCenter)); (**xydat).x = Long2Fix(0); (**xydat).y = Long2Fix(0); PicComment( textCenter, 8, (Handle)xydat); DisposHandle( (Handle)xydat); if (rotnum == 0) drawstring(s); else { saveclip = NewRgn(); GetClip( saveclip); SetRect( &zerorect, 0,0,0,0); ClipRect( &zerorect); drawstring(s); SetClip( saveclip); DisposeRgn( saveclip); drawUpstr( h, v, rotnum, s); } PicComment( textEnd, 0, NULL); } /*textPicDraw*/ #define MAXTRIES 2 #define nextCmd(missing) { \ c2 = c; while (*c2 != 0 & *c2 != ';' & *c2 != 27) c2++; \ missing = (*c2 == 0); } #define nextComma(missing) { \ c2 = c; while (*c2 != 0 & *c2 != ';' & *c2 != ',') c2++; \ if (*c2 != 0) do {++c2;} while (*c2 != 0 & *c2 != ';' & *c2 != ','); \ if (*c2 != 0) do {++c2;} while (*c2 != 0 & *c2 != ';' & *c2 != ','); \ missing = (*c2 == 0); } void fetchmore(Handle hbuf, char **cv, XCmdPtr pXCmd) { Boolean lookagain, newsize; int tries, n2, ce, i, ci; char *c, *c2, *buf2; Handle hbuf2; /* something about callback is messing up local xcmd/plot environ -- the data saved to file & replotted (sometimes) works fine ! */ c = *cv; tries = 0; do { SendHCMessage(pXCmd, "\pset cursor to busy"); hbuf2 = EvalExpr(pXCmd, "\precvTo(empty,45,empty)"); n2 = GetHandleSize(hbuf2); if (n2 < 2) tries++; else { ci = c - *hbuf; /* save index into hbuf */ for (c2 = c; *c2 != 0; c2++) ; /* find end of hbuf */ ce = c2 - *hbuf; /* index to end of current hbuf */ if (n2 + ce > GetHandleSize(hbuf)) { HUnlock(hbuf); SetHandleSize( hbuf, GetHandleSize(hbuf) + n2 + 10000); c2 = *hbuf + ce; /* find end after setsize */ /*if (*c2 != 0) ++c2; */ /* ?? did we get the 0 end */ newsize = true; } else newsize = false; buf2 = *hbuf2; for (i = 0; buf2[i] != 0 & i < n2; i++) { if ( buf2[i] == 3) *c2++ = LBEND; else if (buf2[i] == LBEND | buf2[i] >= 27) *c2++ = buf2[i]; } *c2 = 0; /* tail of new, complete hbuf */ if (i < 1) tries++; if (newsize) { /* SetHandleSize(hbuf, 1 + c2 - *hbuf); */ HLock(hbuf); c = *hbuf + ci; /* restore index into hbuf */ } } DisposHandle(hbuf2); /* done with this */ nextCmd(lookagain); } while (lookagain & tries < MAXTRIES); *cv = c; } /* fetchmore */ #define map2pic(x,y,h,v) { \ h = picrect->left + (x / xscale); \ v = picrect->top + ((ymax - y) / yscale); \ } #define maprel2pic(x,y,h,v) { \ h = (x / xscale); v = (( - y) / yscale); \ } PicHandle hp2pict( Boolean forpage, Rect *picrect, Handle hbuf, WindowPtr myWind, Boolean commfetch, Boolean *alldone, XCmdPtr pXCmd) { char *c, *c2, *ce, *si, s[256]; int cmd, hpx, hpy, x, y, xd, yd, h, v, k, pageno; Boolean dorel, atend, done, lookagain, moveit, penup; Rect wr, hprect; Point pt; float fx, fy, linedash, xscale, yscale; int linetype, ymax, rot = 0; RGBColor bcolor; PicHandle pic; HLock( hbuf); c = (char *) (*hbuf); while ((*c != 0) & (*c != ';')) c++; if (*c == ';') c++; hpx = hpPageX; hpy = hpPageY; redraw: pageno = 0; *alldone = false; pic = OpenPicture(picrect); if (!forpage) { InsetRect( picrect, 10, 8); OffsetRect( picrect, 0, 5); ShowPen(); if (hasColorQD()) { bcolor.red = 56000; bcolor.green= 60000; bcolor.blue = 65000; if (lotsOfColor(myWind)) RGBBackColor( &bcolor); EraseRect( &myWind->portRect); } } SetRect( &wr, -10000, -10000, 30000, 30000); ClipRect(&wr); TextFont(times); if (forpage) TextSize(12); else TextSize(9); laserline(1, 2); PenNormal(); penup = true; dorel = false; linetype = 0; linedash = 1; SetRect( &hprect, 0, 0, hpx, hpy); ymax = hpy; xscale = hpx / (picrect->right - picrect->left); yscale = hpy / (picrect->bottom - picrect->top); done = (*c == 0); while (!done) { while ((!Isalpha(*c)) && (*c != 0)) c++; /* skip to start of cmd */ /* ^^ this messes up '\27.' end of transmission */ cmd = (Toupper(*c++))*256 + (Toupper(*c++)); atend = false; switch (cmd) { case '\27.': /* 6958 == '\27.' */ /* not seen ? */ if (*c == ')') { atend = true; done = true; *alldone = true; *c = 0; SysBeep(2); } break; case 'AF': /* the end-of-plot signal is "AF;\27.)x" */ /* multi-page plots will want me to throw up a new plot window -> from Draw */ if ( (++pageno > 1) | (c[1] == '\27' & c[3] == ')') ) { atend = true; done = true; *c = 0; SysBeep(1); } break; /* autopage */ case 'IN': /* the start-of-plot signal is */ /* "\27.(\27.N;19:\27.I81;;17:IN;...AF;" */ break; /* initialize */ case 'AA': break; /* arc */ case 'IP': break; /* frame */ case 'LB': if (commfetch) { nextCmd(lookagain); if (lookagain) fetchmore(hbuf, &c, pXCmd); } for (si=0; *c != LBEND & si < 256; si++, c++) s[si] = *c; s[si] = 0; /* drawstring(s); */ /* -- use last valid h,v, rot */ /* Note: this h,v is left,top? of string, not center */ textPicDraw( h, v, rot, s); ++c; atend = true; break; /* LBlabel^C; */ case 'LO': x = Strtod( c, &ce); if (ce == c) break; c = ce; break; /* ? Label Offset move ?? */ case 'LT': k = linetype; linetype = 0; if (*c != ';') { linetype = Strtod( c, &ce); if (ce != c) { c = ce; if (*c == ',') c++; linedash = Strtod( c, &ce); c = ce; } } if (linetype != k | linetype > 0) { maprel2pic(linedash,linedash, xd, yd); xd = max( abs(xd), abs(yd)); lineit( linetype, xd); } break; /* LT#,#; line type (style, %diag) */ case 'PU': penup = true; if (*c == ';') break; x = Strtod( c, &ce); if (ce == c) break; c = ce; if (*c == ',') c++; y = Strtod( c, &ce); if (ce == c) break; c = ce; map2pic( x, y, h, v); MoveTo(h,v); break; /* PU[#,#];penup */ case 'PR': /* PR#,#[...]; rel move */ dorel = true; goto penat; case 'PD': /* PD[#,#,...]; pendn */ penup = false; goto penat; /* slide into PA loop */ case 'PA': dorel = false; moveit = (*c != ','); penat: do { if (*c == ',') c++; if (commfetch) { nextComma(lookagain); if (lookagain) fetchmore(hbuf, &c, pXCmd); } /* during commfetch, this loop gets bad, but hbuf data is good !? */ x = Strtod( c, &ce); if (ce == c) break; c = ce; if (*c == ',') c++; y = Strtod( c, &ce); if (ce == c) break; c = ce; if (dorel) { maprel2pic( x, y, h, v); if (penup | moveit) Move(h,v); else Line(h,v); GetPen(&pt); h = pt.h; v = pt.v; /* save for LB */ } else { map2pic( x, y, h, v); if (penup | moveit) MoveTo(h,v); else LineTo(h,v); } moveit = false; } while (true); break; /* PA#,#[,#,#...]; mvabs */ case 'RO': x = Strtod( c, &ce); if ((x > 60 & x < 120) && !forpage) { /* can't do for printed page?? -- need to mangle page orientation in pageSetup... */ hpx = hpPageY; hpy = hpPageX; xd = picrect->right; picrect->right = picrect->bottom; picrect->bottom = xd; if (!forpage) HidePen(); ClosePicture(); KillPicture( pic); xd = myWind->portRect.right - myWind->portRect.left; yd = myWind->portRect.bottom - myWind->portRect.top; SizeWindow( myWind, yd, xd, true); /* need to redraw it NOW ? */ BringToFront( myWind); //BeginUpdate( myWind); //EraseRect( &myWind->portRect); //EndUpdate( myWind); goto redraw; } break; /* RO#; rotate plot */ case 'SP': x = Strtod( c, &ce); switch (x) { /* pen colors should be user option */ /* this form works w/ PICT1(b/w) as well as PICT2 */ default: case 1: ForeColor(blackColor); break; case 2: ForeColor(greenColor); break; case 3: ForeColor(blueColor); break; case 4: ForeColor(redColor); break; case 5: ForeColor(cyanColor); break; case 6: ForeColor(magentaColor); break; case 7: ForeColor(yellowColor); break; case 8: ForeColor(blackColor); break; } /* set color to # */ break; /* SP[#]; select pen */ case 'SI': if (*c == ';') break; fx = Strtod( c, &ce); if (ce == c) break; c = ce; if (*c == ',') c++; fy = Strtod( c, &ce); if (ce == c) break; c = ce; /* map fx,fy into TextSize ?? */ break; /* SI#,#; set text abs width,abs height ? */ case 'DI': rot = 0; if (*c == ';') break; fy = Strtod( c, &ce); if (ce == c) break; c = ce; if (*c == ',') c++; fx = Strtod( c, &ce); if (ce == c) break; c = ce; /* rot == atan2(fx, fy); */ /* left/right rot are reversed !? */ if ((fx == 0.0) & (fy == 0.0)) rot = 360; else if (fx == 0.0) rot = 0; /* ? or 180 */ else if (fy == 0.0) rot = 90; else rot = atan( abs(fx/fy)); if (fy < 0.0) rot = 180 - rot; /*if (fx < 0.0) rot = 360 - abs(rot); */ /* GCG or HPGL is bassackwards on rotation handling */ if (fx > 0.0) rot = 360 - abs(rot); else rot = abs(rot); break; /* DI#,#; text direction */ /* (run = cos(direction), rise = sin(direction) */ case 'SL': break; /* SL[#]; set text slant (tangent) ? */ case 'SC': break; /* scale */ case 'VS': break; /* VS#; pen speed */ case 'CI': /* filled oval */ x = Strtod( c, &ce); if (ce == c) break; c = ce; if (*c == ',') c++; y = Strtod( c, &ce); if (ce == c) break; c = ce; maprel2pic( x+1, y+1, h, v); h = min(h,abs(v)); /* h is bad(huge) for card-sized plot */ GetPen(&pt); SetRect(&wr, pt.h, pt.v, pt.h, pt.v); InsetRect(&wr, -h, -h); /* FillOval(&wr, black); */ PaintOval(&wr); break; default : break; } if (!atend) while ((*c != 0) && (*c != ';') && (!Isalpha(*c))) c++; /* skip to end cmd */ if (*c == ';') c++; if (commfetch & !done) { nextCmd(lookagain); if (lookagain) fetchmore(hbuf, &c, pXCmd); } if (*c == 0) done = true; } if (!forpage) HidePen(); ClosePicture(); HUnlock( hbuf); return pic; } /* hp2pict */